home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 8 / hack.u_init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-27  |  7.1 KB  |  301 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
  2.  
  3. #include "hack.h"
  4. #include <stdio.h>
  5. #include <signal.h>
  6. #define   Strcat   (void) strcat
  7. #define   UNDEF_TYP   0
  8. #define   UNDEF_SPE   (-1)
  9. extern struct obj *addinv();
  10. extern char plname[];
  11.  
  12. char pl_character[PL_CSIZ];
  13.  
  14. struct trobj {
  15.    uchar trotyp;
  16.    schar trspe;
  17.    char trolet;
  18.    Bitfield(trquan,6);
  19.    Bitfield(trknown,1);
  20. };
  21.  
  22. #ifdef WIZARD
  23. struct trobj Extra_objs[] = {
  24.    { 0, 0, 0, 0, 0 },
  25.    { 0, 0, 0, 0, 0 }
  26. };
  27. #endif WIZARD
  28.  
  29. struct trobj Cave_man[] = {
  30.    { MACE, 1, WEAPON_SYM, 1, 1 },
  31.    { BOW, 1, WEAPON_SYM, 1, 1 },
  32.    { ARROW, 0, WEAPON_SYM, 25, 1 },   /* quan is variable */
  33.    { LEATHER_ARMOR, 2, ARMOR_SYM, 1, 1 },
  34.    { 0, 0, 0, 0, 0}
  35. };
  36.  
  37. struct trobj Fighter[] = {
  38.    { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 },
  39.    { RING_MAIL, 3, ARMOR_SYM, 1, 1 },
  40.    { 0, 0, 0, 0, 0 }
  41. };
  42.  
  43. struct trobj Knight[] = {
  44.    { LONG_SWORD, 0, WEAPON_SYM, 1, 1 },
  45.    { SPEAR, 2, WEAPON_SYM, 1, 1 },
  46.    { RING_MAIL, 4, ARMOR_SYM, 1, 1 },
  47.    { HELMET, 1, ARMOR_SYM, 1, 1 },
  48.    { SHIELD, 1, ARMOR_SYM, 1, 1 },
  49.    { PAIR_OF_GLOVES, 1, ARMOR_SYM, 1, 1 },
  50.    { 0, 0, 0, 0, 0 }
  51. };
  52.  
  53. struct trobj Speleologist[] = {
  54.    { STUDDED_LEATHER_ARMOR, 3, ARMOR_SYM, 1, 1 },
  55.    { UNDEF_TYP, 0, POTION_SYM, 2, 0 },
  56.    { FOOD_RATION, 0, FOOD_SYM, 3, 1 },
  57.    { ICE_BOX, 0, TOOL_SYM, 1, 0 },
  58.    { 0, 0, 0, 0, 0}
  59. };
  60.  
  61. struct trobj Tourist[] = {
  62.    { UNDEF_TYP, 0, FOOD_SYM, 10, 1 },
  63.    { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 },
  64.    { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 },
  65.    { DART, 2, WEAPON_SYM, 25, 1 },   /* quan is variable */
  66.    { 0, 0, 0, 0, 0 }
  67. };
  68.  
  69. struct trobj Wizard[] = {
  70.    { ELVEN_CLOAK, 1, ARMOR_SYM, 1, 1 },
  71.    { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 },
  72.    { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 },
  73.    { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 },
  74.    { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 },
  75.    { 0, 0, 0, 0, 0 }
  76. };
  77.  
  78. #ifdef NEWS
  79. int u_in_infl;
  80.  
  81. u_in_intrup()
  82. {
  83.    u_in_infl++;
  84.    (void) signal(SIGINT, u_in_intrup);
  85. }
  86. #endif NEWS
  87.  
  88. u_init(){
  89. register int c,pc,i;
  90. #ifdef NEWS
  91.    /* It is not unlikely that we get an interrupt here
  92.       intended to kill the news; unfortunately this would
  93.       also kill (part of) the following question */
  94. int (*prevsig)() = signal(SIGINT, u_in_intrup);
  95. #endif NEWS
  96. register char *cp;
  97. char buf[256];
  98.    if(pc = pl_character[0]) goto got_suffix;
  99.    buf[0] = 0;
  100.    Strcat(buf, "\nTell me what kind of character you are:\n");
  101.    Strcat(buf, "Are you a Tourist, a Speleologist, a Fighter,\n");
  102.    Strcat(buf, "        a Knight, a Cave-man or a Wizard? [TSFKCW] ");
  103. intrup:
  104.    for(cp = buf; *cp; cp++){
  105. #ifdef NEWS
  106.       if(u_in_infl){
  107.          u_in_infl = 0;
  108.          goto intrup;
  109.       }
  110. #endif NEWS
  111.       (void) myputchar(*cp);
  112.    }
  113. loop:
  114.    (void) myfflush(stdout);
  115.    pc = 0;
  116.    while((c = inchar()) != '\n') {
  117. #ifndef AMIGA
  118.       if(c == EOF) {
  119. #ifdef NEWS
  120.          if(u_in_infl) goto intrup;   /* %% */
  121. #endif NEWS
  122.          settty("\nEnd of input?\n");
  123.          hackexit(0);
  124.          }
  125.       else
  126. #endif !AMIGA
  127.          if(pc && c==8)  /* backspace over it? */
  128.          {
  129.          myputchar(c);
  130.          pc = 0;
  131.          }
  132.       else if (!pc)
  133.          {
  134.          pc = c;
  135.          myputchar(c);
  136.          }
  137.    }
  138.    if(!pc || !strchr("TSFKCWtsfkcw", pc)){
  139.       myprintf("\nAnswer with T,S,F,K,C or W. What are you? ");
  140.       goto loop;
  141.    }
  142. got_suffix:
  143.    if('a' <= pc && pc <= 'z') pc += 'A'-'a';
  144.  
  145. #ifdef NEWS
  146.    (void) signal(SIGINT,prevsig);
  147. #endif NEWS
  148.  
  149.    u.usym = '@';
  150.    u.ulevel = 1;
  151.    init_uhunger();
  152.    u.uhpmax = u.uhp = 12;
  153.    u.ustrmax = u.ustr = !rn2(20) ? 14 + rn2(7) : 16;
  154. #ifdef QUEST
  155.    u.uhorizon = 6;
  156. #endif QUEST
  157.    switch(pc) {
  158.    case 'C':
  159.       setpl_char("Cave-man");
  160.       Cave_man[2].trquan = 12 + rnd(9)*rnd(9);
  161.       u.uhp = u.uhpmax = 16;
  162.       u.ustr = u.ustrmax = 18;
  163.       ini_inv(Cave_man);
  164.       break;
  165.    case 'T':
  166.       setpl_char("Tourist");
  167.       Tourist[3].trquan = 20 + rnd(20);
  168.       u.ugold = u.ugold0 = rnd(1000);
  169.       u.uhp = u.uhpmax = 10;
  170.       u.ustr = u.ustrmax = 8;
  171.       ini_inv(Tourist);
  172.       break;
  173.    case 'W':
  174.       setpl_char("Wizard");
  175.       for(i=1; i<=4; i++) if(!rn2(5))
  176.          Wizard[i].trquan += rn2(3) - 1;
  177.       u.uhp = u.uhpmax = 15;
  178.       u.ustr = u.ustrmax = 16;
  179.       ini_inv(Wizard);
  180.       break;
  181.    case 'S':
  182.       setpl_char("Speleologist");
  183.       Fast = INTRINSIC;
  184.       Stealth = INTRINSIC;
  185.       u.uhp = u.uhpmax = 12;
  186.       u.ustr = u.ustrmax = 10;
  187.       ini_inv(Speleologist);
  188.       break;
  189.    case 'K':
  190.       setpl_char("Knight");
  191.       u.uhp = u.uhpmax = 12;
  192.       u.ustr = u.ustrmax = 10;
  193.       ini_inv(Knight);
  194.       break;
  195.    case 'F':
  196.       setpl_char("Fighter");
  197.       u.uhp = u.uhpmax = 14;
  198.       u.ustr = u.ustrmax = 17;
  199.       ini_inv(Fighter);
  200.    }
  201.    find_ac();
  202.    /* make sure he can carry all he has - especially for T's */
  203.    while(inv_weight() > 0 && u.ustr < 118)
  204.       u.ustr++, u.ustrmax++;
  205. #ifdef WIZARD
  206.    if(wizard) wiz_inv();
  207. #endif WIZARD
  208. }
  209.  
  210. ini_inv(trop) register struct trobj *trop; {
  211. register struct obj *obj;
  212. extern struct obj *mkobj();
  213.    while(trop->trolet) {
  214.       obj = mkobj(trop->trolet);
  215.       obj->known = trop->trknown;
  216.       obj->cursed = 0;
  217.       if(obj->olet == WEAPON_SYM){
  218.          obj->quan = trop->trquan;
  219.          trop->trquan = 1;
  220.       }
  221.       if(trop->trspe != UNDEF_SPE)
  222.          obj->spe = trop->trspe;
  223.       if(trop->trotyp != UNDEF_TYP)
  224.          obj->otyp = trop->trotyp;
  225.       obj->owt = weight(obj);   /* defined after setting otyp+quan */
  226.       obj = addinv(obj);
  227.       if(obj->olet == ARMOR_SYM){
  228.          switch(obj->otyp){
  229.          case SHIELD:
  230.             if(!uarms) setworn(obj, W_ARMS);
  231.             break;
  232.          case HELMET:
  233.             if(!uarmh) setworn(obj, W_ARMH);
  234.             break;
  235.          case PAIR_OF_GLOVES:
  236.             if(!uarmg) setworn(obj, W_ARMG);
  237.             break;
  238.          case ELVEN_CLOAK:
  239.             if(!uarm2)
  240.                setworn(obj, W_ARM);
  241.             break;
  242.          default:
  243.             if(!uarm) setworn(obj, W_ARM);
  244.          }
  245.       }
  246.       if(obj->olet == WEAPON_SYM)
  247.          if(!uwep) setuwep(obj);
  248.       if(--trop->trquan) continue;   /* make a similar object */
  249.       trop++;
  250.    }
  251. }
  252.  
  253. #ifdef WIZARD
  254. wiz_inv(){
  255. register struct trobj *trop = &Extra_objs[0];
  256. extern char *getenv();
  257. register char *ep = getenv("INVENT");
  258. register int type;
  259.    while(ep && *ep) {
  260.       type = atoi(ep);
  261.       ep = strchr(ep, ',');
  262.       if(ep) while(*ep == ',' || *ep == ' ') ep++;
  263.       if(type <= 0 || type > NROFOBJECTS) continue;
  264.       trop->trotyp = type;
  265.       trop->trolet = objects[type].oc_olet;
  266.       trop->trspe = 4;
  267.       trop->trknown = 1;
  268.       trop->trquan = 1;
  269.       ini_inv(trop);
  270.    }
  271.    /* give him a wand of wishing by default */
  272.    trop->trotyp = WAN_WISHING;
  273.    trop->trolet = WAND_SYM;
  274.    trop->trspe = 20;
  275.    trop->trknown = 1;
  276.    trop->trquan = 1;
  277.    ini_inv(trop);
  278. }
  279. #endif WIZARD
  280.  
  281. setpl_char(plc) char *plc; {
  282.    (void) strncpy(pl_character, plc, PL_CSIZ-1);
  283.    pl_character[PL_CSIZ-1] = 0;
  284. }
  285.  
  286. plnamesuffix() {
  287. register char *p;
  288.    if(p = strrchr(plname, '-')) {
  289.       *p = 0;
  290.       if(!plname[0]) {
  291.          askname();
  292.          plnamesuffix();
  293.       }
  294.       if(strchr("TSFKCWtsfkcw", p[1])) {
  295.          pl_character[0] = p[1];
  296.          pl_character[1] = 0;
  297.       }
  298.    }
  299. }
  300.  
  301.